function renderSelectHead(thElem, col) {
    thElem.className = 'et-select-th';
    thElem.innerText = col.title;
}

function renderSelectBody(tdElem, col, rawData) {
    let selectElem = document.createElement('select');
    tdElem.appendChild(selectElem);
    for (let optData of col.select) {
        let optionElem = document.createElement("option");
        optionElem.value = optData.value;
        optionElem.innerHTML = optData.text;
        if (rawData[col.field] == optData.value) optionElem.selected = 'selected';
        selectElem.appendChild(optionElem);
    }
    //编辑渲染
    editable(selectElem,col,rawData);
}

//控件编辑
function editable( selectElem, col, rawData) {
    if (col.editable) {//可编辑
        selectElem.onchange = function () {
            let index = selectElem.selectedIndex; // 选中索引
            let value = selectElem.options[index].value; // 选中值
            rawData[col.field] = value;
        };
    } else {//不可编辑
        selectElem.disabled = true;
    }
}

export { renderSelectHead, renderSelectBody };